<template>
	<view class="content-img">
		<eui-nav-bar title="消息中心" color="#000" rightIcon="" />
		<eui-search-bar ref="approveSearch" v-model="searchValue" @confirm="selStoreById" radius="100"
			placeholder="搜索标题" showFilter>
			<template #searchFields>
				<view class="search-fields">
					<view class="center">
						<!-- <eui-card-input v-model="selectStatus" title="状态" :range="listType" type="radio"
							alignType="left" @buttonClick="buttonClickType" /> -->
						<!-- <eui-card-input v-model="selectTime" :modelValue="selectTime" title="日期" :range="timeList"
							type="radio" alignType="left" @buttonClick="buttonClickTime" />
						<view class="flex date-defined" v-if="selectTime=='自定义'">
							<view class="flex-1"><eui-datetime-picker type="day" v-model="StartDt"
									placeholder="开始日期"></eui-datetime-picker></view>
							<view>-</view>
							<view class="flex-1"><eui-datetime-picker type="day" v-model="EndDt"
									placeholder="结束日期"></eui-datetime-picker></view>
						</view> -->
						<DateCard v-model="selectStatus" :modelValue="selectStatus" title="状态" type="radio"
							:range="listType" @buttonClick="buttonClickStatus"></DateCard>
						<DateCard v-model="selectTime" :modelValue="selectTime" title="日期" type="date" :range="timeList"
							@buttonClick="buttonClickTime"></DateCard>
					</view>
					<view class="bottom flex-1 flex">
						<view class="flex-1 flex" style="padding-right: 7.5px;" @click="CancelCondition">
							<view class="flex-1 flex justify-content-center align-items-center bottom-bg"
								style="border: solid 1rpx rgba(136, 136, 136, 1);font-size: 15px;">重置</view>
						</view>
						<view class="flex-1 flex justify-content-center align-items-center" style="padding-left: 7.5px;"
							@click="ConfirmCondition">
							<view class="flex-1 flex justify-content-center align-items-center bottom-bg button-theme"
								:class="[theme]" style="color: #fff;font-size: 15px;">
								确认</view>
						</view>
						<!-- <eui-button type="max2" title="重置" @click="CancelCondition"></eui-button>
						<eui-button type="max" title="确认" @click="ConfirmCondition"></eui-button> -->
					</view>
				</view>
			</template>
		</eui-search-bar>
		<eui-tab :tabs="tabData" showBadge badgeType="dot" :value="industryTabIndex" @change="tabChange"
			:tabStyle="tabStyle"></eui-tab>
	</view>
	<view class="main-view">
		<scroll-view scroll-y lower-threshold='88' @refresherrefresh="onRefresh" @scrolltolower="templateLower"
			:refresher-enabled='true' :refresher-triggered="triggered" :style="{width:scrollWidth,height:scrollHeight}">
			<view class="approve-list flex flex-direction-column font-size-28 margin-bottom-20"
				v-for="(item,index) in dataList" :key="index">
				<view
					class="flex justify-content-space-between padding-bottom-20 border-bottom-eee padding-left-28 padding-right-28">
					<view class="font-size-28 font-weight-bold flex align-items-center" style="position: relative;">
						<image :src="item.c_icon" class="margin-right-16" style="width: 48rpx;height: 48rpx;" />
						<view class="status-radius margin-right-10" v-if="item.c_status=='未读'"></view>
						{{item.c_type}}消息
					</view>
					<view class="flex align-items-center font-size-24">
						<span class="color-888">{{item.c_dt}}</span>
					</view>
				</view>
				<view class="margin-top-16 padding-left-28 padding-right-28 font-size-32 font-weight-bold">
					{{item.c_title}}
				</view>
				<view
					class="margin-top-16 padding-left-28 padding-right-28 font-size-26 color-888 word-wrap-break-word">
					{{item.c_description}}
				</view>
				<view class="margin-top-16 padding-left-28 padding-right-28 flex justify-content-space-between"
					@click="openApproveList(item)">
					<view><span class="color-888">发送人:</span>[{{item.c_send_userno}}]{{item.c_name}}</view>
					<view><eui-icons color="rgba(136, 136, 136, 1)" size="18" type="forward"></eui-icons></view>
				</view>
			</view>
			<view v-if="dataList.length == 0" class="no-data flex flex-direction-column"
				style="background-color: RGBA(255,255,255,0);">
				<image src="@/static/img/no_data.png" mode="aspectFit" class="image" />
				<view class="color-888 font-size-28">暂无数据</view>
			</view>
		</scroll-view>
	</view>
</template>

<script setup type="ts">
	import { ref } from 'vue';
	import { onLoad,onReady } from '@dcloudio/uni-app';
	import service from '@/common/service';
	import Enjoy from '@/common/enjoy';
	import dateRangUtil from '@/common/dateRangUtil';
	import { storeToRefs } from 'pinia';
	import { useMainStore } from '@/store/modules/store';
	import { useLoginStore } from '@/store/modules/useLoginStore';
	import { useThemeStore } from '@/store/themeStore';
	import DateCard from "@/components/DateCard/index"
	const mainStore = useMainStore();
	const LoginStore = useLoginStore();
	const themeStore = useThemeStore(); // 主题
	const { theme } = storeToRefs(themeStore);
	
	const tabStyle = ref({ justifyContent: 'space-around'});
	const scrollWidth = ref(uni.getSystemInfoSync().windowWidth - 20 + 'px');
	const scrollHeight = ref(uni.getSystemInfoSync().windowHeight + 'px');
	const industryTabIndex = ref(0);
	const searchValue = ref('');
	const triggered = ref(false);
	const dataList = ref([]);
	const tabData = ref([{name:'全部',corner:0},{name:'审批',corner:0},{name:'邮件',corner:0},{name:'通知',corner:0},{name:'公文',corner:0},{name:'任务',corner:0}]);
	const PageSize = ref(10);
	const selectStatus = ref('全部');
	const approveSearch = ref(null);
	const listType = ref([{
		text:'全部',
		value:'全部',
	},{
		text:'未读',
		value:'未读',
	},{
		text:'已读',
		value:'已读',
	}])
	const selectTime = ref('全部');
	const timeList = ref([{
		text: '全部',
		value: '全部',
		dateRang: ['', '']
	},{
		text: "今天",
		value: "今天",
		dateRang: dateRangUtil.getLastToday()
	},{
		text: "昨天",
		value: "昨天",
		dateRang: dateRangUtil.getYesterday()
	},{
		text: "本周",
		value: "本周",
		dateRang: dateRangUtil.getCurrentWeek()
	},{
		text: "上周",
		value: "上周",
		dateRang: dateRangUtil.getLastWeek()
	},{
		text: "近三天",
		value: "近三天",
		dateRang: dateRangUtil.getLast3Day()
	},{
		text: "本月",
		value: "本月",
		dateRang: dateRangUtil.getCurrentMonth()
	},{
		text: "上月",
		value: "上月",
		dateRang: dateRangUtil.getLastMonth()
	},{
		text: "自定义",
		value: "自定义",
		dateRang: "自定义"
	}]);
	const StartDt = ref('');
	const EndDt = ref('');
	const pageList1 = ref({
		CurrentPage: 1, //第几页
		RowsCount: 0, //总条数
		PageCount: 1, //总页数
		data: [],
		cTime: '',
		c_selectTime: '全部',
		c_selectStatus: '全部',
		c_selectType: '全部',
		c_s: '',
		c_e: '',
		sumUnread:0,
	});
	const pageList2 = ref({
		CurrentPage: 1, //第几页
		RowsCount: 0, //总条数
		PageCount: 1, //总页数
		data: [],
		cTime: '',
		c_selectTime: '本周',
		c_selectStatus: '全部',
		c_selectType: '审批',
		c_s: '',
		c_e: '',
		sumUnread:0,
	});
	const pageList3 = ref({
		CurrentPage: 1, //第几页
		RowsCount: 0, //总条数
		PageCount: 1, //总页数
		data: [],
		cTime: '',
		c_selectTime: '本周',
		c_selectStatus: '全部',
		c_selectType: '邮件',
		c_s: '',
		c_e: '',
		sumUnread:0,
	});
	const pageList4 = ref({
		CurrentPage: 1, //第几页
		RowsCount: 0, //总条数
		PageCount: 1, //总页数
		data: [],
		cTime: '',
		c_selectTime: '本周',
		c_selectStatus: '全部',
		c_selectType: '通知',
		c_s: '',
		c_e: '',
		sumUnread:0,
	});
	const pageList5 = ref({
		CurrentPage: 1, //第几页
		RowsCount: 0, //总条数
		PageCount: 1, //总页数
		data: [],
		cTime: '',
		c_selectTime: '本周',
		c_selectStatus: '全部',
		c_selectType: '公文',
		c_s: '',
		c_e: '',
		sumUnread:0,
	});
	const pageList6 = ref({
		CurrentPage: 1, //第几页
		RowsCount: 0, //总条数
		PageCount: 1, //总页数
		data: [],
		cTime: '',
		c_selectTime: '本周',
		c_selectStatus: '全部',
		c_selectType: '任务',
		c_s: '',
		c_e: '',
		sumUnread:0,
	});
	
	const selStoreById =()=>{
		switch (industryTabIndex.value){
			case 0:
				pageList1.value.CurrentPage = 1;
				pageList1.value.data = [];
				pageList1.value.sumUnread = 0;
				onRefresh();
				break;
			case 1:
				pageList2.value.CurrentPage = 1;
				pageList2.value.data = [];
				pageList2.value.sumUnread = 0;
				onRefresh();
				break;
			case 2:
				pageList3.value.CurrentPage = 1;
				pageList3.value.data = [];
				pageList3.value.sumUnread = 0;
				onRefresh();
				break;
			case 3:
				pageList4.value.CurrentPage = 1;
				pageList4.value.data = [];
				pageList4.value.sumUnread = 0;
				onRefresh();
				break;
			case 4:
				pageList5.value.CurrentPage = 1;
				pageList5.value.data = [];
				pageList5.value.sumUnread = 0;
				onRefresh();
				break;
			case 5:
				pageList6.value.CurrentPage = 1;
				pageList6.value.data = [];
				pageList6.value.sumUnread = 0;
				onRefresh();
				break;
			default:
				break;
		}
	}
	const buttonClickStatus = e =>{
		selectStatus.value = e.modelType;
	}
	const buttonClickTime = (e)=>{
		if(e.modelType=='StartDt'){
			selectTime.value='自定义';
			StartDt.value = e.modelValue;
		}else if(e.modelType=='EndDt'){
			selectTime.value='自定义';
			EndDt.value = e.modelValue;
		}else{
			selectTime.value=e.modelType;
		}
	}
	const CancelCondition = () =>{
		switch (industryTabIndex.value) {
			case 0:
				selectTime.value = '全部';
				selectStatus.value = '全部';
				pageList1.value.c_selectTime = '全部';
				pageList1.value.c_selectStatus = '全部';
				pageList1.value.c_s = '';
				pageList1.value.c_e = '';
				break;
			case 1:
				selectTime.value = '本周';
				selectStatus.value = '全部';
				pageList2.value.c_selectTime = '本周';
				pageList2.value.c_selectStatus = '全部';
				pageList2.value.c_s = '';
				pageList2.value.c_e = '';
				break;
			case 2:
				selectTime.value = '本周';
				selectStatus.value = '全部';
				pageList3.value.c_selectTime = '本周';
				pageList3.value.c_selectStatus = '全部';
				pageList3.value.c_s = '';
				pageList3.value.c_e = '';
				break;
			case 3:
				selectTime.value = '本周';
				selectStatus.value = '全部';
				pageList4.value.c_selectTime = '本周';
				pageList4.value.c_selectStatus = '全部';
				pageList4.value.c_s = '';
				pageList4.value.c_e = '';
				break;
			case 4:
				selectTime.value = '本周';
				selectStatus.value = '全部';
				pageList5.value.c_selectTime = '本周';
				pageList5.value.c_selectStatus = '全部';
				pageList5.value.c_s = '';
				pageList5.value.c_e = '';
				break;
			case 5:
				selectTime.value = '本周';
				selectStatus.value = '全部';
				pageList6.value.c_selectTime = '本周';
				pageList6.value.c_selectStatus = '全部';
				pageList6.value.c_s = '';
				pageList6.value.c_e = '';
				break;
		}
		StartDt.value = '';
		EndDt.value = '';
	}
	const ConfirmCondition = ()=>{
		if(selectTime.value=='自定义'){
			if(!StartDt.value||!EndDt.value){
				uni.showToast({
					duration: 3500,
					icon: 'none',
					title: '请选择开始日期、结束日期!',
				});
				return false;
			}
		}else{
			StartDt.value = '';
			EndDt.value = '';
		}
		approveSearch.value.closeDrawer();
		
		switch (industryTabIndex.value){
			case 0:
				pageList1.value.CurrentPage = 1;
				pageList1.value.data = [];
				pageList1.value.c_selectTime=selectTime.value;
				pageList1.value.c_selectStatus=selectStatus.value;
				pageList1.value.c_s = StartDt.value;
				pageList1.value.c_e = EndDt.value;
				pageList1.value.sumUnread = 0;
				GetUserMessage();
				break;
			case 1:
				pageList2.value.CurrentPage = 1;
				pageList2.value.data = [];
				pageList2.value.c_selectTime=selectTime.value;
				pageList2.value.c_selectStatus=selectStatus.value;
				pageList2.value.c_s = StartDt.value;
				pageList2.value.c_e = EndDt.value;
				pageList2.value.sumUnread = 0;
				GetUserMessage();
				break;
			case 2:
				pageList3.value.CurrentPage = 1;
				pageList3.value.data = [];
				pageList3.value.c_selectTime=selectTime.value;
				pageList3.value.c_selectStatus=selectStatus.value;
				pageList3.value.c_s = StartDt.value;
				pageList3.value.c_e = EndDt.value;
				pageList3.value.sumUnread = 0;
				GetUserMessage();
				break;
			case 3:
				pageList4.value.CurrentPage = 1;
				pageList4.value.data = [];
				pageList4.value.c_selectTime=selectTime.value;
				pageList4.value.c_selectStatus=selectStatus.value;
				pageList4.value.c_s = StartDt.value;
				pageList4.value.c_e = EndDt.value;
				pageList4.value.sumUnread = 0;
				GetUserMessage();
				break;
			case 4:
				pageList5.value.CurrentPage = 1;
				pageList5.value.data = [];
				pageList5.value.c_selectTime=selectTime.value;
				pageList5.value.c_selectStatus=selectStatus.value;
				pageList5.value.c_s = StartDt.value;
				pageList5.value.c_e = EndDt.value;
				pageList5.value.sumUnread = 0;
				GetUserMessage();
				break;
			case 5:
				pageList6.value.CurrentPage = 1;
				pageList6.value.data = [];
				pageList6.value.c_selectTime=selectTime.value;
				pageList6.value.c_selectStatus=selectStatus.value;
				pageList6.value.c_s = StartDt.value;
				pageList6.value.c_e = EndDt.value;
				pageList6.value.sumUnread = 0;
				GetUserMessage();
				break;
			default:
				break;
		}
	}
	const tabChange =e=>{
		switch (e) {
			case 0:
				selectTime.value = pageList1.value.c_selectTime;
				selectStatus.value = pageList1.value.c_selectStatus;
				StartDt.value = pageList1.value.c_s;
				EndDt.value = pageList1.value.c_e;
				break;
			case 1:
				selectTime.value = pageList2.value.c_selectTime;
				selectStatus.value = pageList2.value.c_selectStatus;
				StartDt.value = pageList2.value.c_s;
				EndDt.value = pageList2.value.c_e;
				break;
			case 2:
				selectTime.value = pageList3.value.c_selectTime;
				selectStatus.value = pageList3.value.c_selectStatus;
				StartDt.value = pageList3.value.c_s;
				EndDt.value = pageList3.value.c_e;
				break;
			case 3:
				selectTime.value = pageList4.value.c_selectTime;
				selectStatus.value = pageList4.value.c_selectStatus;
				StartDt.value = pageList4.value.c_s;
				EndDt.value = pageList4.value.c_e;
				break;
			case 4:
				selectTime.value = pageList5.value.c_selectTime;
				selectStatus.value = pageList5.value.c_selectStatus;
				StartDt.value = pageList5.value.c_s;
				EndDt.value = pageList5.value.c_e;
				break;
			case 5:
				selectTime.value = pageList6.value.c_selectTime;
				selectStatus.value = pageList6.value.c_selectStatus;
				StartDt.value = pageList6.value.c_s;
				EndDt.value = pageList6.value.c_e;
				break;
		}
		if (industryTabIndex.value !== e) {
			industryTabIndex.value = e;
			switch (e){
				case 0:
					if (pageList1.value.cTime) {
						let minute = 0;
						minute = Math.floor((new Date() - pageList1.value.cTime) / (60 * 1000))
						console.log("上次查询距现在相差分钟数：" + minute)
						if (minute >= 1) {
							pageList1.value.CurrentPage = 1;
							pageList1.value.data = [];
							pageList1.value.sumUnread = 0;
							GetUserMessage();
						} else {
							dataList.value = pageList1.value.data;
						}
					} else {
						pageList1.value.CurrentPage = 1;
						pageList1.value.data = [];
						pageList1.value.sumUnread = 0;
						GetUserMessage();
					}
					break;
				case 1:
					if (pageList2.value.cTime) {
						let minute = 0;
						minute = Math.floor((new Date() - pageList2.value.cTime) / (60 * 1000))
						console.log("上次查询距现在相差分钟数：" + minute)
						if (minute >= 1) {
							pageList2.value.CurrentPage = 1;
							pageList2.value.data = [];
							pageList2.value.sumUnread = 0;
							GetUserMessage();
						} else {
							dataList.value = pageList2.value.data;
						}
					} else {
						pageList2.value.CurrentPage = 1;
						pageList2.value.data = [];
						pageList2.value.sumUnread = 0;
						GetUserMessage();
					}
					break;
				case 2:
					if (pageList3.value.cTime) {
						let minute = 0;
						minute = Math.floor((new Date() - pageList3.value.cTime) / (60 * 1000))
						console.log("上次查询距现在相差分钟数：" + minute)
						if (minute >= 1) {
							pageList3.value.CurrentPage = 1;
							pageList3.value.data = [];
							pageList3.value.sumUnread = 0;
							GetUserMessage();
						} else {
							dataList.value = pageList3.value.data;
						}
					} else {
						pageList3.value.CurrentPage = 1;
						pageList3.value.data = [];
						pageList3.value.sumUnread = 0;
						GetUserMessage();
					}
					
					break;
				case 3:
					if (pageList4.value.cTime) {
						let minute = 0;
						minute = Math.floor((new Date() - pageList4.value.cTime) / (60 * 1000))
						console.log("上次查询距现在相差分钟数：" + minute)
						if (minute >= 1) {
							pageList4.value.CurrentPage = 1;
							pageList4.value.data = [];
							pageList4.value.sumUnread = 0;
							GetUserMessage();
						} else {
							dataList.value = pageList4.value.data;
						}
					} else {
						pageList4.value.CurrentPage = 1;
						pageList4.value.data = [];
						pageList4.value.sumUnread = 0;
						GetUserMessage();
					}
					break;
				case 4:
					if (pageList5.value.cTime) {
						let minute = 0;
						minute = Math.floor((new Date() - pageList5.value.cTime) / (60 * 1000))
						console.log("上次查询距现在相差分钟数：" + minute)
						if (minute >= 1) {
							pageList5.value.CurrentPage = 1;
							pageList5.value.data = [];
							pageList5.value.sumUnread = 0;
							GetUserMessage();
						} else {
							dataList.value = pageList5.value.data;
						}
					} else {
						pageList5.value.CurrentPage = 1;
						pageList5.value.data = [];
						pageList5.value.sumUnread = 0;
						GetUserMessage();
					}
					break;
				case 5:
					if (pageList6.value.cTime) {
						let minute = 0;
						minute = Math.floor((new Date() - pageList6.value.cTime) / (60 * 1000))
						console.log("上次查询距现在相差分钟数：" + minute)
						if (minute >= 1) {
							pageList6.value.CurrentPage = 1;
							pageList6.value.data = [];
							pageList6.value.sumUnread = 0;
							GetUserMessage();
						} else {
							dataList.value = pageList6.value.data;
						}
					} else {
						pageList6.value.CurrentPage = 1;
						pageList6.value.data = [];
						pageList6.value.sumUnread = 0;
						GetUserMessage();
					}
					break;
				default:
					break;
			}
		}
	}
	const buttonClickType = e =>{
		selectStatus.value=e.modelValue
	}
	// 下拉刷新
	const onRefresh = ()=>{
		if (triggered.value) {
			return false;
		};
		triggered.value = true;
		switch (industryTabIndex.value) {
			case 0:
				pageList1.value.CurrentPage = 1;
				pageList1.value.data = [];
				pageList1.value.sumUnread = 0;
				GetUserMessage();
				break;
			case 1:
				pageList2.value.CurrentPage = 1;
				pageList2.value.data = [];
				pageList2.value.sumUnread = 0;
				GetUserMessage();
				break;
			case 2:
				pageList3.value.CurrentPage = 1;
				pageList3.value.data = [];
				pageList3.value.sumUnread = 0;
				GetUserMessage();
				break;
			case 3:
				pageList4.value.CurrentPage = 1;
				pageList4.value.data = [];
				pageList4.value.sumUnread = 0;
				GetUserMessage();
				break;
			case 4:
				pageList5.value.CurrentPage = 1;
				pageList5.value.data = [];
				pageList5.value.sumUnread = 0;
				GetUserMessage();
				break;
			case 5:
				pageList6.value.CurrentPage = 1;
				pageList6.value.data = [];
				pageList6.value.sumUnread = 0;
				GetUserMessage();
				break;
		}
		setTimeout(() => {
			triggered.value = false;
		}, 1000)
	}
	// 加载更多
	const templateLower = ()=>{
		switch (industryTabIndex.value) {
			case 0:
				if (pageList1.value.CurrentPage < pageList1.value.PageCount) {
					pageList1.value.CurrentPage = pageList1.value.CurrentPage + 1;
					GetUserMessage();
				}
				break;
			case 1:
				if (pageList2.value.CurrentPage < pageList2.value.PageCount) {
					pageList2.value.CurrentPage = pageList2.value.CurrentPage + 1;
					GetUserMessage();
				}
				break;
			case 2:
				if (pageList3.value.CurrentPage < pageList3.value.PageCount) {
					pageList3.value.CurrentPage = pageList3.value.CurrentPage + 1;
					GetUserMessage();
				}
				break;
			case 3:
				if (pageList4.value.CurrentPage < pageList4.value.PageCount) {
					pageList4.value.CurrentPage = pageList4.value.CurrentPage + 1;
					GetUserMessage();
				}
				break;
			case 4:
				if (pageList5.value.CurrentPage < pageList5.value.PageCount) {
					pageList5.value.CurrentPage = pageList5.value.CurrentPage + 1;
					GetUserMessage();
				}
				break;
			case 5:
				if (pageList6.value.CurrentPage < pageList6.value.PageCount) {
					pageList6.value.CurrentPage = pageList6.value.CurrentPage + 1;
					GetUserMessage();
				}
				break;
		}
	}
	const openApproveList = (e)=>{
		console.log(JSON.stringify(e))
		// 仅支持邮件公文审批打开详情
		if (e.c_type == '邮件') {
			updateInformation(e.c_identity)
			openemaill(e)
		} else if (e.c_type == '审批') {
			updateInformation(e.c_identity)
			openapprove(e)
		} else if (e.c_type == '公文') {
			updateInformation(e.c_identity)
			openDocument(e)
		}
	}
	// 跳转邮件详情
	const openemaill = data =>{
		let emailDetail = [];
		emailDetail.push({
			msgid: data.c_key,
			fromList: 'UnRead.html'
		})
		let request = {
		    url: LoginStore.EnjoyMain,
		    data: {
		        UniqueKey: "管易通40推送消息",
				ObjectData: {
					c_identity: '',
					c_key: data.c_key,//data.c_key
					c_type: '',
					c_userno: mainStore.loginInfo.sUser && mainStore.loginInfo.sUser != '' && mainStore.loginInfo.sUser !=
						null ? mainStore.loginInfo.sUser :
						'0006', //用于苹果审核特殊处理获取不到用户时默认按0006账号获取this.loginInfo.sUser
				},
		        MethodName: "ModifyMsgToRead",
		    },
		}
		service.request(request, (res) => {
		    if (res && res.data) {
		        if (!res.data.HasException) {
					// 增加模块使用日志
					const list = {
						c_mdcode: data.c_key,
						c_title: '',
						c_name: '',
					};
					AddModuleUseLog(list);
					onRefresh();
					uni.navigateTo({
						url: '/pages/OaViews/Email/EmailDetail?id=' + data.c_key + '&selType=收件箱' + '&industryTabIndex=2'
					});
		        } else {
		            service.enjoyShowToast(res.data.Exception.Message)
		        }
		    }
			service.enjoyHideLoading();
		}, () => {
			service.enjoyHideLoading();
		    console.log('失败')
		});
	}
	// 跳转审批详情
	const openapprove = data =>{
		service.enjoyShowLoading('正在加载...');
		let request = {
		    url: LoginStore.EnjoyMain,
		    data: {
		        UniqueKey: "管易通40推送消息",
		        ObjectData: {
					ID: data.c_key,
				},
		        MethodName: "GetApproveInfo",
		    },
		}
		service.request(request, (res) => {
		    if (res && res.data) {
		        if (!res.data.HasException) {
					const ObjectData = res.data.ObjectData;
					let lstApproveBill = [];
					for (var i = 0; i < ObjectData.length; i++) {
						let item = ObjectData[i];
						lstApproveBill.push({
							...item,
							SortKey: i,
							UserNo: mainStore.loginInfo.sUser,
							AppParamType: 3
						});
					}
					UpdateApproveReadStatus(lstApproveBill[0]);
					uni.navigateTo({
						url: '/pages/OaViews/Approve/ApproveDetail?item=' + JSON.stringify(lstApproveBill[0]) + '&tabIndex=' + (lstApproveBill[0].ReplyStatus=='未回复'?0:1)
					});
		        } else {
		            service.enjoyShowToast(res.data.Exception.Message)
		        }
		    }
			service.enjoyHideLoading();
		}, () => {
			service.enjoyHideLoading();
		    console.log('失败')
		});
	}
	const UpdateApproveReadStatus = e =>{
		let request = {
		    url: LoginStore.EnjoyMain,
		    data: {
		        UniqueKey: "管易通40审批",
		        ObjectData: {
					AppRecvId: e.AppRecvId,
					MsgRecvId: e.MsgRecvId,
					MsgId: e.MsgId,
					AppUserNo: mainStore.loginInfo.sUser
				},
		        MethodName: "UpdateApproveReadStatus",
		    },
		}
		service.request(request, (res) => {
		    if (res && res.data) {
		        if (!res.data.HasException) {
					onRefresh();
		        } else {
		            service.enjoyShowToast(res.data.Exception.Message)
		        }
		    }
		}, () => {
		    console.log('失败')
		});
	}
	const updateInformation = c_identity =>{
		let request = {
		    url: LoginStore.EnjoyMain,
		    data: {
		        UniqueKey: "管易通40推送消息",
		        ObjectData: {
					c_identity
				},
		        MethodName: "ModifyMsgToRead",
		    },
		}
		service.request(request, (res) => {
		    if (res && res.data) {
		        if (!res.data.HasException) {
					onRefresh();
		        } else {
		            service.enjoyShowToast(res.data.Exception.Message)
		        }
		    }
		}, () => {
		    console.log('失败')
		});
	}
	const openDocument = data =>{
		uni.navigateTo({
			url: '/pages/OaViews/Document/DocDetail?id=' + data.c_key+ '&c_id=' + data.c_identity
		});
	}
	// 增加模块使用日志
	const AddModuleUseLog = data =>{
		let computername = '';
		let ip = '';
		// #ifdef APP-PLUS
		computername = plus.device.model;
		ip = plus.device.uuid;
		// #endif
		let request = {
		    url: LoginStore.EnjoyMain,
		    data: {
		        UniqueKey: "管易通40公共",
		        ObjectData: {
					c_username: mainStore.loginInfo.sUserName,
					c_userno: mainStore.loginInfo.sUser && mainStore.loginInfo.sUser != '' && mainStore.loginInfo.sUser !=
						null ? mainStore.loginInfo.sUser :
						'0006', //用于苹果审核特殊处理获取不到用户时默认按0006账号获取this.loginInfo.sUser,
					c_mdcode: data.c_mdcode,
					c_mdcname: data.c_title,
					c_computername: computername,
					c_enter_dt: null,
					c_guid: "",
					c_ip: ip,
					c_leave_dt: null,
					c_login_sessionid: "",
					c_mdname: data.c_name,
					c_menu_code: '',
					c_menu_role: "管易通应用",
					c_note: ""
				},
		        MethodName: "AddModuleUseLog",
		    },
		}
		service.request(request, (res) => {
		    if (res && res.data) {
		        if (!res.data.HasException) {
					const ObjectData = res.data.ObjectData;
		        } else {
		            service.enjoyShowToast(res.data.Exception.Message)
		        }
		    }
		}, () => {
		    console.log('失败')
		});
	}
	const setMessageIcon = e =>{
		let url = '';
		switch (e){
			case '考勤':
				url = '../../../static/img/message/message_center_kq.png';
				break;
			case '邮件':
			case '公文':
				url = '../../../static/img/message/message_center_yj.png';
				break;
			case '通知':
				url = '../../../static/img/message/message_center_tz.png';
				break;
			case '审批':
				url = '../../../static/img/message/message_center_sp.png';
				break;
			case '任务':
				url = '../../../static/img/message/message_center_rw.png';
				break;
			default:
				url = '../../../static/img/message/message_center_tz.png';
				break;
		}
		return url;
	}
	const GetUserMessageSumUnread =Obj=>{
		let request = {
		    url: LoginStore.EnjoyMain,
		    data: {
		        UniqueKey: "管易通40推送消息",
		        ObjectData: Obj,
		        MethodName: "GetUserMessageSumUnread",
		    },
		}
		service.request(request, (res) => {
		    if (res && res.data) {
		        if (!res.data.HasException) {
					const ObjectData = res.data.ObjectData;
					console.log("ObjectData: " + JSON.stringify(ObjectData));
					if(ObjectData.length>0){
						let allCount = 0;
						for (let i = 0; i < ObjectData.length; i++) {
							allCount+=ObjectData[i].SumUnread*1;
							switch (ObjectData[i].c_type){
								case '审批':
									pageList2.value.sumUnread = ObjectData[i].SumUnread;
									tabData.value[1].corner = ObjectData[i].SumUnread;
									break;
								case '邮件':
									pageList3.value.sumUnread = ObjectData[i].SumUnread;
									tabData.value[2].corner = ObjectData[i].SumUnread;
									break;
								case '通知':
									pageList4.value.sumUnread = ObjectData[i].SumUnread;
									tabData.value[3].corner = ObjectData[i].SumUnread;
									break;
								case '公文':
									pageList5.value.sumUnread = ObjectData[i].SumUnread;
									tabData.value[4].corner = ObjectData[i].SumUnread;
									break;
								case '任务':
									pageList6.value.sumUnread = ObjectData[i].SumUnread;
									tabData.value[5].corner = ObjectData[i].SumUnread;
									break;
								default:
									break;
							}
						}
						pageList1.value.sumUnread = allCount;
						tabData.value[0].corner = allCount;
					}else{
						pageList1.value.sumUnread = 0;
						tabData.value[0].corner = 0;
						pageList2.value.sumUnread = 0;
						tabData.value[1].corner = 0;
						pageList3.value.sumUnread = 0;
						tabData.value[2].corner = 0;
						pageList4.value.sumUnread = 0;
						tabData.value[3].corner = 0;
						pageList5.value.sumUnread = 0;
						tabData.value[4].corner = 0;
						pageList6.value.sumUnread = 0;
						tabData.value[5].corner = 0;
					}
		        } else {
		            service.enjoyShowToast(res.data.Exception.Message)
		        }
		    }
			service.enjoyHideLoading();
		}, () => {
			service.enjoyHideLoading();
		    console.log('失败')
		});
	}
	const GetUserMessage =()=>{
		service.enjoyShowLoading('正在加载...');
		let page = {};
		switch (industryTabIndex.value){
			case 0:
				page = JSON.parse(JSON.stringify(pageList1.value));
				break;
			case 1:
				page= JSON.parse(JSON.stringify(pageList2.value));
				break;
			case 2:
				page= JSON.parse(JSON.stringify(pageList3.value));
				break;
			case 3:
				page= JSON.parse(JSON.stringify(pageList4.value));
				break;
			case 4:
				page= JSON.parse(JSON.stringify(pageList5.value));
				break;
			case 5:
				page= JSON.parse(JSON.stringify(pageList6.value));
				break;
			default:
				break;
		}
		let st = '';
		let en = '';
		if(page.c_selectTime=='自定义'){
			st = page.c_s;
			en = page.c_e;
		} else if (page.c_selectTime=='全部'){
			st = '';
			en = '';
		} else {
			let list = timeList.value.filter(item => item.value==page.c_selectTime);
			if(list.length>0){
				st = list[0].dateRang[0];
				en = page.c_selectTime=='上周'?list[0].dateRang[2]:list[0].dateRang[1];
			}
		}
		const Obj = {
			IsNotPage: false,
			PageSize: PageSize.value,
			UserNo:mainStore.loginInfo.sUser,
			ID:'2e5476732b07d168836b71a5190a62c5',//plus.push.getClientInfo().clientid,
			ConstDate:dateRangUtil.formatDate('','YYYY-MM-DD HH:mm:ss'),
			
			Status:page.c_selectStatus=='全部'?'':page.c_selectStatus,
			Type:page.c_selectType=='全部'?'':page.c_selectType,
			DateFrom:st,
			DateTo:en,
			Extends:searchValue.value,
			...page
		}
		let request = {
		    url: LoginStore.EnjoyMain,
		    data: {
		        UniqueKey: "管易通40推送消息",
		        ObjectData: Obj,
		        MethodName: "GetUserMessage",
		    },
		}
		GetUserMessageSumUnread(Obj);
		service.request(request, (res) => {
		    if (res && res.data) {
		        if (!res.data.HasException) {
					const ObjectData = res.data.ObjectData;
					page.RowsCount = ObjectData.RowsCount;
					page.PageCount = ObjectData.PageCount;
					page.CurrentPage = ObjectData.CurrentPage;
					page.cTime = new Date();
					if (ObjectData.CurrentPage === 1) {
						page.data = []
					}
					for (let i = 0; i < ObjectData.ReturnObject.length; i++) {
						if(ObjectData.ReturnObject[i].c_status=='未读'){
							page.sumUnread+=1;
						}
						page.data.push({
							...ObjectData.ReturnObject[i],
							c_icon:setMessageIcon(ObjectData.ReturnObject[i].c_type)
						})
					}
					dataList.value = page.data;
					switch (industryTabIndex.value){
						case 0:
							pageList1.value = page;
							break;
						case 1:
							pageList2.value = page;
							break;
						case 2:
							pageList3.value = page;
							break;
						case 3:
							pageList4.value = page;
							break;
						case 4:
							pageList5.value = page;
							break;
						case 5:
							pageList6.value = page;
							break;
						default:
							break;
					}
					tabData.value[industryTabIndex.value].corner = page.sumUnread;
		        } else {
		            service.enjoyShowToast(res.data.Exception.Message)
		        }
		    }
			service.enjoyHideLoading();
		}, () => {
			service.enjoyHideLoading();
		    console.log('失败')
		});
	}
	onReady(()=>{
		uni.getSystemInfo({
			success: function(res) {
				const userInfoPage = uni.createSelectorQuery().select(".content-img");
				userInfoPage.boundingClientRect(function(data) {
					scrollHeight.value = (res.windowHeight - data.height - 20)+'px';
				}).exec()
			}
		});
	})
	onLoad(()=>{
		GetUserMessage();
	})
	defineExpose({
		onRefresh
	})
</script>

<style lang="scss" scoped>
	@import '@/main.scss';

	.content-img {
		background-color: #FFFFFF;
		background-repeat: no-repeat;
		width: 100%;
	}

	.main-view {
		flex: 1;
		flex-direction: column;
		padding: 20rpx;
		background-color: #f2f2f2;
	}

	.approve-list {
		padding: 28rpx 0rpx 24rpx 0rpx;
		border-radius: 20rpx;
		background-color: #fff;
	}

	.flex {
		display: flex;
	}

	.flex-1 {
		flex: 1;
	}

	.flex-direction-column {
		flex-direction: column !important;
	}

	.font-size-24 {
		font-size: 24rpx;
	}

	.font-size-26 {
		font-size: 26rpx;
	}

	.font-size-28 {
		font-size: 28rpx;
	}

	.font-size-32 {
		font-size: 32rpx;
	}

	.font-weight-bold {
		font-weight: bold;
	}

	.margin-top-16 {
		margin-top: 16rpx;
	}

	.margin-right-16 {
		margin-right: 16rpx;
	}

	.margin-bottom-20 {
		margin-bottom: 20rpx;
	}

	.padding-bottom-20 {
		padding-bottom: 20rpx;
	}

	.padding-left-28 {
		padding-left: 28rpx;
	}

	.padding-right-28 {
		padding-right: 28rpx;
	}

	.justify-content-space-between {
		justify-content: space-between !important;
	}

	.align-items-center {
		align-items: center !important;
	}

	.color-888 {
		color: rgba(136, 136, 136, 1);
	}

	.color-FF4000 {
		color: rgba(255, 64, 0, 1);
	}

	.color-02B7E6 {
		color: rgba(2, 183, 230, 1);
	}

	.border-bottom-eee {
		border-bottom: solid 1px rgba(238, 238, 238, 1);
	}

	.approve-mark {
		font-size: 26rpx;
		padding: 1px 7px;
		background-color: RGBA(242, 251, 254, 1);
		border-radius: 18px;
	}

	.search-fields {
		width: 100%;
		background: #FFFFFF;

		.center {
			padding-bottom: 22rpx;
		}

		.bottom {
			background: #ffffff;
			border-top: 1rpx solid $uni-line-color;
			display: flex;
			justify-content: center;
			padding: 20rpx;
		}
	}

	.date-defined {
		padding-left: 185rpx;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
		font-size: 14px;
	}

	.word-wrap-break-word {
		word-wrap: break-word;
	}

	.justify-content-center {
		justify-content: center;
	}

	.bottom-bg {
		height: 40px;
		border-radius: 20px;
	}

	.status-radius {
		width: 8px;
		height: 8px;
		border-radius: 50%;
		background-color: rgba(255, 64, 0, 1);
		position: absolute;
		top: -3px;
		left: 18px;
	}

	.margin-right-10 {
		margin-right: 10rpx;
	}

	.button-theme {
		background: var(--theme-bgc-color);
	}
</style>